<?php
namespace API\Controller;
use Think\Controller;
class UserController extends Controller
{

/*1.用户登录*/
  public function getUserLogin(){
    $u_phone=$_GET['u_phone'];
    $u_pwd=$_GET['u_pwd'];
    $usersModel=M('users');
    $getUserById=$usersModel->where("u_phone='$u_phone' and u_pwd='$u_pwd'" )->select();
    
 $str=json_encode($getUserById[0][u_id]);
    if($getUserById){
      echo ('{"u_id":');
      echo($str);
      echo ('}');
    }else {
      echo('{"u_id","0"}');  
    }
  }


/*2.用户注册*/
    Public function getUserRegister(){
    $data['u_name']=$_GET['u_name'];
    $data['u_phone']=$_GET['u_phone'];
    $usersModel=M('users'); 
    $telnum = $usersModel -> where('u_phone ='.$data['u_phone']) -> count();
    $temp['u_name'] = $data['u_name'];
    $namenum = $usersModel -> where($temp) -> count();
    if(0 == $namenum){  
      if(0 == $telnum){
    $data['u_address']=I('get.u_address');  
    $data['u_email']=I('get.u_email');  
    $data['u_personal']=I('get.u_personal');     
    $data['u_pwd']=$_GET['u_pwd'];
    $data['u_time'] = array('exp','now()');                     
    $users=$usersModel->add($data);
    if(false !=$users){          
           $senting = array('success'=>1);
            echo json_encode($senting);
    }else{
        //$this->false;
          $senting = array('success'=>0);
            echo json_encode($senting);
    }   
   }
   else{
           $senting = array('success'=>3);
            echo json_encode($senting);
            /**电话号码已被占用 */
   }
 }
  else{
          $senting = array('success'=>2);
            echo json_encode($senting);
              /**用户名已被占用 */
          
 }
}



 /*3.查看用户个人的信息*/
      public function getUserInfo(){
      $u_id=$_GET['u_id'];
      $usersmodel=M('users');
      $users=$usersmodel->find($u_id); 
      $this->users=$users;
      echo json_encode($users);
    } 


/*4.查看自己的发帖信息*/
     public function getMyArticleslist(){   
     $u_id=$_GET['u_id'];
     $articlesmodel=M('articles');
     $articles=$articlesmodel->table('vm_articles a,vm_users u')->where("a.u_id=$u_id and a.u_id=u.u_id")->field('a.*,u.u_name')->select();
        //调用视图层显示数据
     $this->articles=$articles;
     echo json_encode($articles);
    }



/*5.查看自己参加的活动列表*/
  public function getMyActOrderlist(){   
     $u_id=$_GET['u_id'];
     $entermodel=M('enter');
     $enter=$entermodel->table('vm_enter e,vm_users u,vm_activity a')->where("e.u_id=$u_id and e.act_id=a.act_id and e.u_id=u.u_id")->field('e.*,u.u_name,a.act_name,a.act_pic')->select();
        //调用视图层显示数据
     $this->enter=$enter;
     echo json_encode($enter);
    }


/*6.查看自己获奖的活动列表*/
 public function getMyLuckyActOrderlist(){   
     $u_id=$_GET['u_id'];
     $entermodel=M('enter');
     $enter=$entermodel->table('vm_enter e,vm_users u,vm_activity a')->where("e.u_id=$u_id and e.act_id=a.act_id and e.u_id=u.u_id and e.e_state=1 ")->field('e.*,u.u_name,a.act_name,a.*')->select();
        //调用视图层显示数据
     $this->enter=$enter;
     echo json_encode($enter);
    }



/*7.查看自己报名的活动详情*/
public function getMyActOrderdetail(){
        $u_id=$_GET['u_id'];
         $act_id=$_GET['act_id'];
       
        $entermodel=M('enter');
        $enter=$entermodel->table('vm_enter e')->where("e.u_id=$u_id and e.act_id=$act_id ")->select();
     
        $this->enter=$enter;
        $this->ajaxReturn($enter,'JSON');

    }



 // /*8.查看我关注的电影列表*/
 //    public function getMyCollectMovies(){
 //      $u_id=$_GET['u_id'];
 //      $flag=$_GET['flag'];
 //      $collectmodel=M('collect');
 //      $collect=$collectmodel->table('vm_movies m,vm_collect c,vm_users u')->where("c.u_id=$u_id and c.collect_flag=$flag and c.collect_id=m.m_id and c.u_id=u.u_id and col_state=1")->field('m.*,c.*')->select();
 //      $this->collect=$collect;
 //      echo json_encode($collect);
 //    }



 //    /*9.查看我关注的用户列表*/
 //    public function getMyCollectUsers(){
 //      $u_id=$_GET['u_id'];
 //      $flag=$_GET['flag'];
 //      $Usersmodel=M('users');
 //      $collect=$Usersmodel->table('vm_users m,vm_collect c,vm_users u')->where("c.u_id=$u_id and c.collect_flag=$flag and c.collect_id=m.u_id and c.u_id=u.u_id and col_state=1")->field('m.*,c.*')->select();
 //      $this->collect=$collect;
 //      echo json_encode($collect);
 //    }


 // /*10.查看我关注的文章列表*/
 //    public function getMyCollectArticles(){
 //      $u_id=$_GET['u_id'];
 //      $flag=$_GET['flag'];
 //      $collectmodel=M('collect');
 //      $collect=$collectmodel->table('vm_articles a,vm_collect c,vm_users u')->where("c.u_id=$u_id and c.collect_flag=$flag and c.collect_id=a.a_id and c.u_id=u.u_id and col_state=1")->field('a.*,c.*')->select();
 //      $this->collect=$collect;
 //      echo json_encode($collect);
 //    }



   
/*10.修改个人信息*/
     public function edituser(){
      $u_id=$_GET['u_id'];
      $usermodel=M('users');
      $users=$usermodel->find($u_id); 
      $this->users=$users;
      echo json_encode($users);
    }
    
  Public function updateuser(){
    $data['u_id']=$_GET['u_id'];
    $data['u_name']=$_GET['u_name'];
    $data['u_pwd']=$_GET['u_pwd'];
    $data['u_phone']=$_GET['u_phone'];
    $data['u_email']=$_GET['u_email']; 
    $data['u_address']=$_GET['u_address'];
    $data['u_time'] =  date("Y-m-d H:i:s"); 
    $usersmodel=M('users');                                          
    $users=$usersmodel->save($data);
    if(false !==$users){   
    echo('{"success":"1"}');
    }else{
        //$this->false;
    echo('{"success","0"}');
    }
    }

    


    /*11.发表反馈*/
    public function addfeedback(){

    $data['f_id']=$_GET['f_id'];
    $data['u_id']=$_GET['u_id'];
    $data['f_info']=$_GET['f_info'];
    $data['f_time'] =  date("Y-m-d H:i:s"); 
    $feedbackmodel=M('feedback');                                         
    $feedback=$feedbackmodel->add($data);
    if(false !==$feedback){   
        echo('{"success":"1"}');
    }else{
        //$this->false;
         echo('{"success","0"}');
    }

}

 /*12.查看关于我APP*/
    public function aboutme(){
     $aboutmodel=M('about');
     $about=$aboutmodel->find($about_id);
     $this->ajaxReturn($about,'JSON');


}


   
/*13.修改个性签名信息*/
     public function edituserpersonal(){
      $u_id=$_GET['u_id'];
      $usermodel=M('users');
      $users=$usermodel->find($u_id); 
      $this->users=$users;
      echo json_encode($users);
    }
    
  Public function updateuserpersonal(){
    $data['u_id']=$_GET['u_id'];
    $data['u_personal']=$_GET['u_personal'];  
    $usersmodel=M('users');                                          
    $users=$usersmodel->save($data);
    if(false !==$users){   
    echo('{"success":"1"}');
    }else{
        //$this->false;
    echo('{"success","0"}');
    }
    }





  }
